# -*- coding: utf-8 -*-
from openerp.osv import osv, fields

# 提货记录导出
class send_sms_wizard(osv.osv_memory):
    _name = 'send.sms.wizard'
    _columns = {
        'message': fields.text(u'提示信息'),

        'state': fields.boolean(u'send_sms')
    }

    def _set_default_message(self, cr, uid, context=None):
        return '本次选中发送短信条数 %s 条' % (len(context.get('active_ids')))

    _defaults = {
        'message': _set_default_message
    }

    def send_sms(self, cr, uid, ids, context=None):
        applivery_obj= self.pool.get('apply.delivery')
        all_nums, success_nums, ignore_num, fail_num = applivery_obj.delivery_send_sms(cr, uid, context.get('active_ids'),
                                                                                       context=context)
        return_mssage = "1.本次选中%s提货记录\n 2.发送成功%s条 \n3. 忽略发送%s \n 4.发送失败%s条" % (all_nums, success_nums, ignore_num, fail_num)
        self.write(cr, uid, ids, {'message': return_mssage, 'state': True}, context=context)
        return {
            'type': 'ir.actions.act_window',
            'res_model': 'send.sms.wizard',
            'view_mode': 'form',
            'view_type': 'form',
            'res_id': ids[0],
            'views': [(False, 'form')],
            'target': 'new',
        }


